<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" id="rowId" th:value="${id}" class="layui-input">
    <input type="hidden" id="oldParentId" name="oldParentId" th:value="${parentId}" class="layui-input">

    <input type="hidden" id="type" name="type" th:value="${type}" class="layui-input">
    <input type="hidden" id="parentId" name="parentId" th:value="${parentId}" class="layui-input">
    <div th:if="${type} < 3" class="layui-form-item">
        <label class="layui-form-label required">同级/子级</label>
        <div class="layui-input-block">
            <div class="layui-input-block">
                <input type="radio" name="level" th:value="${type}" title="同级" checked="checked"
                       lay-filter="levelRadio1">
                <input type="radio" name="level" th:value="${type}+1" title="子级" lay-filter="levelRadio2">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">资源名称</label>
        <div class="layui-input-block">
            <input type="text" name="resourceName" lay-verify="required" lay-reqtext="资源名称不能为空" placeholder="请输入资源名称"
                   value=""
                   class="layui-input">
            <!--            <tip>填写资源名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <input type="text" name="permission" placeholder="权限标识" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源图标</label>
        <div class="layui-input-block">
            <input type="text" name="icon" placeholder="资源图标" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源链接</label>
        <div class="layui-input-block">
            <input type="text" name="url" placeholder="资源链接" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-layer-btn-c">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'common'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/admin/resource',
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg('操作成功', {time: 500}, function () {
                            // 刷新列表
                            window.back();
                        });
                    }
                },
            });
            return false;
        });

        //监听radio
        form.on('radio(levelRadio1)', function (data) {
            $("#type").val(data.value);
            $("#parentId").val($("#oldParentId").val());
        });
        form.on('radio(levelRadio2)', function (data) {
            $("#type").val(data.value);
            $("#parentId").val($("#rowId").val());
        });

    });
</script>
</body>
</html>